﻿using System.Data;
using System.Data.SqlClient;
using System.Text;
using Microsoft.ApplicationBlocks.Data;
using System.Configuration;
using System;

namespace Customs.Components.GC
{
	/// <summary>
	/// Phụ kiện.
	/// </summary>
	public class PhuKienDangKy
	{
		public static DataSet GetDanhSach(string maHaiQuan, string maDoanhNghiep)
		{
            
            DataSet ds =(GetDanhSachPhuKienDangKy(maHaiQuan, maDoanhNghiep));                       
			return ds;						
		}
        public static DataSet GetDanhSach(string maHaiQuan, string maDoanhNghiep, string sohopdong, DateTime ngayky)
        {
            DataSet ds = GetDanhSachPhuKienDangKyOfHopDong(maHaiQuan, maDoanhNghiep, sohopdong, ngayky);          
            return ds;
        }
        public static DataSet GetDanhSachPhuKienDangKy(string maHaiQuan, string maDoanhNghiep)
		{
            string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString_SLXNK"].ConnectionString;
            StringBuilder query = new StringBuilder();
			query.Append("SELECT ");
			query.Append("PK.So_HD			AS SoHopDong, ");
			query.Append("PK.Ma_HQHD		AS MaHaiQuan, ");
			query.Append("PK.DVGC			AS MaDoanhNghiep, ");
			query.Append("PK.Ngay_Ky		AS NgayKy, ");
			query.Append("PK.So_PK			AS SoPhuKien, ");
            query.Append("PK.Ngay_PK	    AS NgayPhuKien, ");
			query.Append("PK.Ma_PK			AS LoaiPhuKien, ");
			query.Append("PK.So_TN			AS SoTiepNhan, ");
            query.Append("PK.Ngay_TN		AS NgayTiepNhan, ");
			query.Append("PK.Noi_Dung		AS NoiDung, ");
            query.Append("PK.VBCP			AS VBCP, ");
            query.Append("PK.GhiChu			AS GhiChu, ");
			query.Append("PK.Old_Info		AS ThongTinCu, ");
			query.Append("PK.New_Info		AS ThongTinMoi ");			
            query.Append("FROM DPKHDGC PK ");
			query.Append("WHERE ");
			query.Append("PK.Ma_HQHD = @MaHaiQuan AND ");
			query.Append("PK.DVGC = @MaDoanhNghiep");

			SqlParameter[] parameters = new SqlParameter[2];

			parameters[0] = new SqlParameter("@MaHaiQuan", SqlDbType.Char, 6);
			parameters[0].Value = maHaiQuan;

			parameters[1] = new SqlParameter("@MaDoanhNghiep", SqlDbType.VarChar, 14);
			parameters[1].Value = maDoanhNghiep;

            return SqlHelper.ExecuteDataset(connectionString, CommandType.Text, query.ToString(), parameters);
		}

        public static DataSet GetDanhSachPhuKienDangKyOfHopDong(string maHaiQuan, string maDoanhNghiep, string sohopdong, DateTime ngayky)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString_SLXNK"].ConnectionString;
            StringBuilder query = new StringBuilder();
            query.Append("SELECT ");
            query.Append("PK.So_HD			AS SoHopDong, ");
            query.Append("PK.Ma_HQHD		AS MaHaiQuan, ");
            query.Append("PK.DVGC			AS MaDoanhNghiep, ");
            query.Append("PK.Ngay_Ky		AS NgayKy, ");
            query.Append("PK.So_PK			AS SoPhuKien, ");
            query.Append("PK.Ngay_PK	    AS NgayPhuKien, ");
            query.Append("PK.Ma_PK			AS LoaiPhuKien, ");
            query.Append("PK.So_TN			AS SoTiepNhan, ");
            query.Append("PK.Ngay_TN		AS NgayTiepNhan, ");
            query.Append("PK.Noi_Dung		AS NoiDung, ");
            query.Append("PK.VBCP			AS VBCP, ");
            query.Append("PK.GhiChu			AS GhiChu, ");
            query.Append("PK.Old_Info		AS ThongTinCu, ");
            query.Append("PK.New_Info		AS ThongTinMoi ");	
            query.Append("FROM DPKHDGC PK ");
            query.Append("WHERE ");
            query.Append("PK.Ma_HQHD = @MaHaiQuan AND ");
            query.Append("PK.DVGC = @MaDoanhNghiep AND ");
            query.Append("PK.Ngay_Ky = @Ngay_Ky AND " );
            query.Append("PK.So_HD = @So_HD");

            SqlParameter[] parameters = new SqlParameter[4];

            parameters[0] = new SqlParameter("@MaHaiQuan", SqlDbType.Char, 6);
            parameters[0].Value = maHaiQuan;

            parameters[1] = new SqlParameter("@MaDoanhNghiep", SqlDbType.VarChar, 14);
            parameters[1].Value = maDoanhNghiep;

            parameters[2] = new SqlParameter("@Ngay_Ky", SqlDbType.DateTime);
            parameters[2].Value = ngayky;

            parameters[3] = new SqlParameter("@So_HD", SqlDbType.VarChar);
            parameters[3].Value = sohopdong;

            return SqlHelper.ExecuteDataset(connectionString, CommandType.Text, query.ToString(), parameters);
        }
	}
}
